package model.backup.handlers;

import database.Database;
import java.sql.SQLException;
import model.backup.BackupTombstone;

/**
 * Denne klasse bruges til at hente al data i bs_tombstone_order og returnere det
 * @author junjie
 */
public abstract class BackupTombstoneHandler {
    
    /**
     * Henter alle rækker i bs_tombstone_order og returnerer et BackupTombstone[] model
     * @return BackupTombstone[]
     * @throws ClassNotFoundException
     * @throws SQLException 
     */
    public static BackupTombstone[] getTombstone() throws ClassNotFoundException, SQLException{
        BackupTombstone[] tombstoneArray = null;
        
        Database db = new Database();
        
        String[][] result = db.getFromDB("bs_tombstone_order", "", "", "", "id", "cuffin", "area", "the_row", "the_number", "old_name", "inscription", "font", "repaint", 
                                         "commission", "mortician_commission_no", "fk_mortician_id", "fk_grave_yard_id");
        tombstoneArray = new BackupTombstone[result.length];
        
        db.closeDB();
        
        for(int i = 0; i<result.length; i++){
            
            int morticianID;
            if (result[i][11] == null)
            {
                morticianID = 0;
            }
            else
            {
                morticianID = Integer.parseInt(result[i][11]);
            }
            
            int graveyardID;
            if (result[i][11] == null)
            {
                graveyardID = 0;
            }
            else
            {
                graveyardID = Integer.parseInt(result[i][11]);
            }
            
            tombstoneArray[i] = new BackupTombstone(Integer.parseInt(result[i][0]), Integer.parseInt(result[i][1]), result[i][2], Integer.parseInt(result[i][3]),
                                                    Integer.parseInt(result[i][4]), result[i][5], result[i][6], result[i][7], Integer.parseInt(result[i][8]),
                                                    Double.parseDouble(result[i][9]), Integer.parseInt(result[i][10]), morticianID,
                                                    graveyardID);
        }
        return tombstoneArray;
    }
}
